package dangan;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import org.junit.jupiter.api.Test;

import dangan.Bean.StudentBean;

public class danganguanli {

	private static List<StudentBean> studentlist = new ArrayList();

	public static void main(String[] args) {
		while (true) {
			System.out.println("1.录入学生信息");
			System.out.println("2.查看学生信息");
			System.out.println("3.按学生姓名查询学生信息");
			System.out.println("4.按专业查询学生信息");
			System.out.println("请输入要进行的操作");
			danganguanli d = new danganguanli();
			d.caozuo();
		}

	}

	public void caozuo() {
		Scanner scanner = new Scanner(System.in);
		String xuanze = scanner.nextLine();
		
		switch (xuanze) {
		case "1":
			insert();
			break;
		case "2":
			selectAll(studentlist);
			break;
		case "3":
			selectByName(studentlist);
			break;
		case "4":
			selectByZhuan(studentlist);
			break;
		default:
			break;
		}
	}

	@Test
	public void insert() {
		StudentBean stu = new StudentBean();
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入学生id号");
		int id = Integer.parseInt(sc.nextLine());
		System.out.println("请输入学生姓名");
		String name = sc.nextLine();
		System.out.println("请输入学生专业");
		String zhuanye = sc.nextLine();
		System.out.println("请输入学生性别");
		int sex = 0;
		String xingbie = sc.nextLine();
		if (xingbie.equals("男")) {
			sex = 0;
		} else {
			sex = 1;
		}
		stu.setId(id);
		stu.setName(name);
		stu.setZhuanye(zhuanye);
		stu.setSex(sex);
		studentlist.add(stu);
//		for (int i = 0; i < studentlist.size(); i++) {
//			System.out.println(studentlist.get(i).toString());
//		}
//		System.out.println(studentlist.get(0).toString());
	}
	@Test
	public void selectAll(List<StudentBean> studentlist) {

		System.out.println("所有学生信息");
		System.out.println(studentlist.size());
		for (int i = 0; i < studentlist.size(); i++) {
			int sex = studentlist.get(i).getSex();
			String xing="男";
			if(sex==1) {
				xing="女";
			}
			System.out.println(studentlist.get(i).toString());
		}

	}

	public void selectByName(List<StudentBean> studentlist) {

		Scanner sc = new Scanner(System.in);
		System.out.println("请输入学生姓名");
		String name = sc.nextLine();
		StudentBean stu = new StudentBean();
		for (int i = 0; i < studentlist.size(); i++) {
			stu = studentlist.get(i);
			if (stu.getName().equals(name)) {
				System.out.println(stu.toString());
			}
		}
	}

	public void selectByZhuan(List<StudentBean> studentlist) {
		Scanner sc = new Scanner(System.in);
		System.out.println("请输入学生专业");
		String zhuanye = sc.nextLine();
		StudentBean stu = new StudentBean();
		for (int i = 0; i < studentlist.size(); i++) {
			stu = studentlist.get(i);
			if (stu.getZhuanye().equals(zhuanye)) {
				System.out.println(stu.toString());
			}
		}
	}

}
